import 'package:enterprise_v6_app/app/components/special_operation/custom_approval_node_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_gas_count_down_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_function.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_ticket/common/common_process/common_job_approval/common_job_approval_controller.dart';

///作业通用-作业审批
///[isChange] 是否在交接班中
class CommonJobApprovalPage extends StatelessWidget {
  CommonJobApprovalPage({super.key, this.isEnabled = false, this.isChange = false}){
    Get.lazyPut(CommonJobApprovalController.new);
  }

  //节点是否可编辑
  final bool isEnabled;

  // 是否在交接班中
  final bool isChange;

  @override
  Widget build(BuildContext context) {
    final controller = Get.find<CommonJobApprovalController>();
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            margin: EdgeInsets.only(bottom: 60.w),
            color: const Color(0xFFF5F5F6),
            child: Column(
              children: [
                Visibility(
                  visible: controller.milliseconds != 0,
                  child: CustomGasCountDownPage(milliseconds: controller.milliseconds),
                ),
                Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(8.w),
                  ),
                  margin: EdgeInsets.only(top: 12.w, left: 14.w, right: 14.w),
                  padding: EdgeInsets.symmetric(horizontal: 12.w),
                  child: CustomSelectPage(
                      title: '作业开始时间',
                      isEnabled: isEnabled && !isChange,
                      selectText: controller.workAllPageController.executeEntity.startDate ?? '',
                      onCallBack: () {
                        CustomSelectFunction.selectDateTime(onCallBack: (String value) {
                          controller.workAllPageController.executeEntity.startDate = value;
                          controller.update();
                        });
                      }),
                ),
                Expanded(
                    child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
                  // margin: EdgeInsets.only(bottom: 60.w),
                  color: const Color(0xFFF5F5F6),
                  alignment: Alignment.topCenter,
                  child: ListView.separated(
                    itemCount: controller.workCheckList.length,
                    itemBuilder: (context, index) {
                      //如果当前进度小于index，或为完工验收，不显示
                      if (controller.currentlyProgress < index || controller.workCheckList[index].checkProject == '完工验收') {
                        return Container();
                      }
                      return CustomApprovalNodePage(
                        isEnabled: isEnabled && !isChange,
                        workCheck: controller.workCheckList[index],
                        onCallBack: () {
                          controller.updateCurrentlyProgress();
                        },
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return AppGaps.vGap20;
                    },
                  ),
                ))
              ],
            ),
          );
        });
  }
}
